Distinct var declaration proposal: x @= 3#5477
Draft
cosmicexplorer wants to merge 7 commits intojashkenas:mainfrom
Draft
Distinct var declaration proposal: x @= 3#5477cosmicexplorer wants to merge 7 commits intojashkenas:mainfrom
cosmicexplorer wants to merge 7 commits intojashkenas:mainfrom
Conversation
- annotate delimiter pairing logic - generate a var statement for the given node - [FIX!] update scope to use positions and call .type() recursively! this fixes the following code: ```coffee import x from "./lib/coffeescript/index.js" do -> x = 3 x ``` - rename "scope" to FunctionScope - break out a separate TopLevelScope so we can look at modules more clearly - add lots of TODOs and fix namedMethod?() - remove extraneous 9e9 limit from .splice call - add quite a lot of notes to compileWithDeclarations - add block scopes!!!! - imports and exports are so much better supported now!!! - assigning to an imported symbol is an error
Contributor
|
FYI: #5395 offers an alternative approach, which is to attach the comment to the first assignment to the variable. I'm not sure it's worth adding additional syntax when a simple rule like this might suffice. In any case I think this is worth a discussion. (However, I never revised #5395 so it's in hiatus now, though it's still used by CoffeeSense I believe. Feel free to pick it up if it's of interest. Or I could try if there's interest. My efforts have mostly shifted to Civet.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a
+55/-0(very small!) diff on top of #5475: see the comparison at https://github.com/cosmicexplorer/coffeescript/compare/scope-refactoring...cosmicexplorer:coffeescript:distinct-var-decl?expand=1.Problem
We would like to be able to attach JSDoc comments to variable declarations for two reasons:
.d.ts) for our exported interfaces.As discussed in the thread at #5307 (comment), the current mechanism of generating
vardeclarations implicitly and declaring them all at once in a single statement at the top of the function means users are unable to associate a block comment with a specific variable declaration (we currently coalesce all comments in assignments together on top of the singlevarstatement):We want to be able to associate that particular comments with
xandxalone.Solution
With #5475, this becomes much easier:
@=) and a new node (Declaration) to separate it fromAssignbehavior entirely.@=is only called at the top level of avarscope (either a function scope or the top-level scope).@=is the first assignment in the scope, and that there is exactly one@=in the scope for a given variable name.Result
For valid distinct declarations, block comments are correctly assigned to the output so that JSDoc syntax can be observed:
tscintegration prototypeI have added a script
build-support/typescript-compile.coffeewhich performs typechecking againsttscand rewrites error locations using source maps. I'm not sure how reliable this technique is since I don't really know how source maps are supposed to work, but it seems to work in extremely small examples: